from config import *

class UploadProduct:
	def GET(self):
		return render.UploadProduct()
	def POST(self):
		input = web.input()
		
		web.debug('*' * 90)
		web.debug(input)

		
	
class UploadProductPic:
	def GET(self):
		return render.UploadProductPic()
	
	def POST(self):
		input = web.input(imgFile = {})
		
		#web.debug('*' * 90)
		#web.debug(input['localUrl'])
		#web.debug(input['imgFile'].filename)
		#web.debug(len(input['imgFile'].value))
		
		filedir = TMP_IMAGE
		if 'imgFile' in input:
			filename = str(web.ctx.session.userID) + '_' + input['imgFile'].filename
			fout = open(filedir + '/' + filename, 'wb')
			fout.write(input['imgFile'].value)
			fout.close()
			success_json = '{"error" : 0, "url" : "%s"}' % (filedir + '/' + filename)
			return success_json
		fail_json = '{"error" : 1, "message" : "error message"}'
		return success_json 		